package controls;


import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;


public class GamePad
{
   private static Controller gamePadInstance = null;

   /**
    * return true if init was successful, false else
    * 
    * @return
    */
   public static boolean isGamePadConnected()
   {
      Controller[] ca = ControllerEnvironment.getDefaultEnvironment()
            .getControllers();
      boolean isConnected = false;

      for (int i = 0; i < ca.length; i++)
      {

         if (ca[i].getType() == Controller.Type.GAMEPAD)
         {
            isConnected = true;
         }
      }
      return isConnected;
   }

   public static Controller getGamePadInstance()
   {
      Controller[] ca = ControllerEnvironment.getDefaultEnvironment()
            .getControllers();
      if (gamePadInstance == null)
      {
         for (int i = 0; i < ca.length; i++)
         {

            if (ca[i].getType() == Controller.Type.GAMEPAD)
            {

               gamePadInstance = ca[i];

            }
         }
      }
      return gamePadInstance;
   }
}
